//获取订单详细
var urlOrderDetail = server_host + '/userweb/getUserOrderDetail.do';
//订单号
var orderNum = getParameterByName('orderNum');

var appModule = angular.module('CheerHiWx', []);
appModule.controller('OkOrderCtrl', ['$scope', '$http', function($scope, $http) {

	$scope.loadOrderDetail = function() {
		$http.get(urlOrderDetail + '?orderNum=' + orderNum).success(function(data, status, headers, config) {
			console.log(data);
			$scope.orderDetails = data.data;
		});
	}

	$scope.backToShoplist = function() {
		location.href = 'index.html?brandId=' + $scope.orderDetails.brandId;
	}

	// 去付款去掉
	// $scope.goPay = function() {
	// 	location.href = 'pay-way.html?orderNum=' + orderNum;
	// }

	$scope.goMeal = function() {
		location.href = 'order-foodinfo.html?orderNum=' + orderNum + '&fr=order'
	}

	$scope.loadOrderDetail();

}]);

function wxJssdkInit() {
	$.ajax({
		type: 'POST',
		dataType: 'json',
		url: server_host + '/h5wx/getWxTicket.do?url=' + encodeURIComponent(location.href.split('#')[0]),
		success: function(data) {
			wx.config({
				debug: false,
				appId: wxAppId,
				timestamp: data.timestamp,
				nonceStr: data.nonceStr,
				signature: data.signature,
				jsApiList: wxJsApi
			});
			var orderDetails = angular.element(document.body).scope().orderDetails;
			wx.onMenuShareAppMessage({
				title: orderDetails.shareTitle, // 分享标题
				desc: orderDetails.shareMsmContent, // 分享描述
				link: orderDetails.shareUrl, // 分享链接
				imgUrl: orderDetails.shareImg, // 分享图标
				type: 'link', // 分享类型,music、video或link，不填默认为link
				dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
				success: function() {
					alert('分享成功！');
				},
				cancel: function() {
					// 用户取消分享后执行的回调函数
				}
			});
			wx.onMenuShareTimeline({
				title: orderDetails.shareTitle, // 分享标题
				link: orderDetails.shareUrl, // 分享链接
				imgUrl: orderDetails.shareImg, // 分享图标
				success: function() {
					alert('分享成功！');
				},
				cancel: function() {
					// 用户取消分享后执行的回调函数
				}
			});
			wx.onMenuShareQQ({
				title: orderDetails.shareTitle, // 分享标题
				desc: orderDetails.shareMsmContent, // 分享描述
				link: orderDetails.shareUrl, // 分享链接
				imgUrl: orderDetails.shareImg, // 分享图标
				success: function() {
					alert('分享成功！');
				},
				cancel: function() {
					// 用户取消分享后执行的回调函数
				}
			});
		}
	});
}

if (typeof WeixinJSBridge == "undefined") {
	if (document.addEventListener) {
		document.addEventListener('WeixinJSBridgeReady', wxJssdkInit, false);
	} else if (document.attachEvent) {
		document.attachEvent('WeixinJSBridgeReady', wxJssdkInit);
		document.attachEvent('onWeixinJSBridgeReady', wxJssdkInit);
	}
} else {
	wxJssdkInit();
}